Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
Imports DataAccesGenerales
Imports DataAcces

Public Class DataAccesMovimientos_Planeados
  Private Const consTimeOut As Integer = 0 

    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla Movimientos_Planeados
    ''' </summary>
   Public Function Movimientos_Planeados_InsertarModificar(pptda_mov_plan As Long, ptipo_maniobra As String, pmaniobrista As Long, pnaviera As Long, pag_aduanal As Long, pganchos As Long, ptons As Long, ppct_camiones As Long, ppct_ffcc As Long, pcamiones As Long, pffcc As Long, pobs As String, pf_ini_op As String, pf_fin_op As String, pno_pasajeros As Long, pfatraqueposible As String, ppct_almacen As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosInsertarModificar"
          oraCommandDocumentos.Parameters.Add("pptda_mov_plan", pptda_mov_plan)
          oraCommandDocumentos.Parameters.Add("ptipo_maniobra", ptipo_maniobra)
          oraCommandDocumentos.Parameters.Add("pmaniobrista", pmaniobrista)
          oraCommandDocumentos.Parameters.Add("pnaviera", pnaviera)
          oraCommandDocumentos.Parameters.Add("pag_aduanal", pag_aduanal)
          oraCommandDocumentos.Parameters.Add("pganchos", pganchos)
          oraCommandDocumentos.Parameters.Add("ptons", ptons)
          oraCommandDocumentos.Parameters.Add("ppct_camiones", ppct_camiones)
          oraCommandDocumentos.Parameters.Add("ppct_ffcc", ppct_ffcc)
          oraCommandDocumentos.Parameters.Add("pcamiones", pcamiones)
          oraCommandDocumentos.Parameters.Add("pffcc", pffcc)
          oraCommandDocumentos.Parameters.Add("pobs", pobs)
          oraCommandDocumentos.Parameters.Add("pf_ini_op", pf_ini_op)
          oraCommandDocumentos.Parameters.Add("pf_fin_op", pf_fin_op)
          oraCommandDocumentos.Parameters.Add("pno_pasajeros", pno_pasajeros)
          oraCommandDocumentos.Parameters.Add("pfatraqueposible", pfatraqueposible)
          oraCommandDocumentos.Parameters.Add("ppct_almacen", ppct_almacen)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para consultar un registro de la tabla Movimientos_Planeados
    ''' </summary>
    ''' <param name="pNidDocumento">numero de documento</param>
    ''' <returns>DataTable</returns>
    ''' <remarks></remarks>
   Public Function Movimientos_Planeados_Consultar(pNidDocumento As Long) As DataTable
        Dim dtResultado As New DataTable("Movimientos_PlaneadosConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosConsultar"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la cadena XML Chilkat del documento de la tabla Movimientos_Planeados
    ''' </summary>
    ''' <param name="nidDocumento"> numero del documento</param>
    ''' <returns>Chilkat.Xml</returns>
    ''' <remarks></remarks>
   Public Function Movimientos_Planeados_CadenaOriginalXMLChilkat(nidDocumento As Long) As Chilkat.Xml
        Dim detalleDataSet As New DataSet("DatosMovimientos_Planeados")
        Try
      detalleDataSet = Movimientos_Planeados_DetalleXML(nidDocumento)
            'En esta parte van las tablas obtenidas en la consulta anterior
            'separadas dependiendo del reporte a crear, ejemplo:
            detalleDataSet.Tables(0).TableName = "Informacion del Tramite"
            detalleDataSet.Tables(1).TableName = "Datos Movimientos_Planeados"
            detalleDataSet.Tables(2).TableName = "Archivos Anexos"
            detalleDataSet.Tables(3).TableName = "Incidencias"

            Dim xml As New Chilkat.Xml
            xml.LoadXml(detalleDataSet.GetXml())
            Return xml 'detalleDataSet.GetXml()
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' Funcion para consultar el detalle del documento de la tabla Movimientos_Planeados
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>DataSet</returns>
    ''' <remarks></remarks>
   Public Function Movimientos_Planeados_DetalleXML(pNidDocumento As Long) As DataSet
        Dim dsDetalle As New DataSet("Movimientos_PlaneadosDetalle")
        Dim pTransaccion As Byte = 0
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosDetalleXML"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    'En esta parte es para los cursores necesario 
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pEncabezado", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pDatos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pAnexos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pIncidencias", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    'pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraDataAdapter.Fill(dsDetalle)
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dsDetalle
    End Function
  
   Public Function Movimientos_Planeados_DatosBase() As DataTable
        Dim dtResultado As New DataTable("Movimientos_PlaneadosConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosDatosBase"
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla Movimientos_Planeados
    ''' </summary>
   Public Function Movimientos_Planeados_Insertar(pptda_mov_plan As Long, ptipo_maniobra As String, pmaniobrista As Long, pnaviera As Long, pag_aduanal As Long, pganchos As Long, ptons As Long, ppct_camiones As Long, ppct_ffcc As Long, pcamiones As Long, pffcc As Long, pobs As String, pf_ini_op As String, pf_fin_op As String, pno_pasajeros As Long, pfatraqueposible As String, ppct_almacen As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosInsertar"
          oraCommandDocumentos.Parameters.Add("pptda_mov_plan", pptda_mov_plan)
          oraCommandDocumentos.Parameters.Add("ptipo_maniobra", ptipo_maniobra)
          oraCommandDocumentos.Parameters.Add("pmaniobrista", pmaniobrista)
          oraCommandDocumentos.Parameters.Add("pnaviera", pnaviera)
          oraCommandDocumentos.Parameters.Add("pag_aduanal", pag_aduanal)
          oraCommandDocumentos.Parameters.Add("pganchos", pganchos)
          oraCommandDocumentos.Parameters.Add("ptons", ptons)
          oraCommandDocumentos.Parameters.Add("ppct_camiones", ppct_camiones)
          oraCommandDocumentos.Parameters.Add("ppct_ffcc", ppct_ffcc)
          oraCommandDocumentos.Parameters.Add("pcamiones", pcamiones)
          oraCommandDocumentos.Parameters.Add("pffcc", pffcc)
          oraCommandDocumentos.Parameters.Add("pobs", pobs)
          oraCommandDocumentos.Parameters.Add("pf_ini_op", pf_ini_op)
          oraCommandDocumentos.Parameters.Add("pf_fin_op", pf_fin_op)
          oraCommandDocumentos.Parameters.Add("pno_pasajeros", pno_pasajeros)
          oraCommandDocumentos.Parameters.Add("pfatraqueposible", pfatraqueposible)
          oraCommandDocumentos.Parameters.Add("ppct_almacen", ppct_almacen)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function

    ''' <summary>
    ''' Funcion para Modificar un regristro en la tabla Movimientos_Planeados
    ''' </summary>
   Public Function Movimientos_Planeados_Modificar(pptda_mov_plan As Long, ptipo_maniobra As String, pmaniobrista As Long, pnaviera As Long, pag_aduanal As Long, pganchos As Long, ptons As Long, ppct_camiones As Long, ppct_ffcc As Long, pcamiones As Long, pffcc As Long, pobs As String, pf_ini_op As String, pf_fin_op As String, pno_pasajeros As Long, pfatraqueposible As String, ppct_almacen As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosModificar"
          oraCommandDocumentos.Parameters.Add("pptda_mov_plan", pptda_mov_plan)
          oraCommandDocumentos.Parameters.Add("ptipo_maniobra", ptipo_maniobra)
          oraCommandDocumentos.Parameters.Add("pmaniobrista", pmaniobrista)
          oraCommandDocumentos.Parameters.Add("pnaviera", pnaviera)
          oraCommandDocumentos.Parameters.Add("pag_aduanal", pag_aduanal)
          oraCommandDocumentos.Parameters.Add("pganchos", pganchos)
          oraCommandDocumentos.Parameters.Add("ptons", ptons)
          oraCommandDocumentos.Parameters.Add("ppct_camiones", ppct_camiones)
          oraCommandDocumentos.Parameters.Add("ppct_ffcc", ppct_ffcc)
          oraCommandDocumentos.Parameters.Add("pcamiones", pcamiones)
          oraCommandDocumentos.Parameters.Add("pffcc", pffcc)
          oraCommandDocumentos.Parameters.Add("pobs", pobs)
          oraCommandDocumentos.Parameters.Add("pf_ini_op", pf_ini_op)
          oraCommandDocumentos.Parameters.Add("pf_fin_op", pf_fin_op)
          oraCommandDocumentos.Parameters.Add("pno_pasajeros", pno_pasajeros)
          oraCommandDocumentos.Parameters.Add("pfatraqueposible", pfatraqueposible)
          oraCommandDocumentos.Parameters.Add("ppct_almacen", ppct_almacen)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para generar un combo de la tabla Movimientos_Planeados
    ''' </summary>
    ''' <param name="pNombre">nombre a buscar en la tabla</param>
    ''' <returns>DataTable</returns>
    ''' <remarks>si el nombre es "" retornara todos los registros</remarks>
   Public Function Movimientos_Planeados_Combo(pNombre As String) As DataTable
        Dim dtResultado As New DataTable("Movimientos_PlaneadosCombo")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosCombo"
                    oraCommandDocumentos.Parameters.Add("pNombre", pNombre)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la integracion del documento de la tabla Movimientos_Planeados
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>Byte</returns>
    ''' <remarks></remarks>
   Public Function Movimientos_Planeados_Integracion(pNidDocumento As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosIntegracion"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
   Public Function Movimientos_Planeados_Borrar(pnid As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Movimientos_PlaneadosBorrar"
                    oraCommandDocumentos.Parameters.Add("pnid", pnid)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
  
End Class
